#include <iostream>
#include <map>
#include <string>
#include <fstream>
#include <sstream>
#include <ostream>
using namespace std;
struct Record
{
    string _word;
    int _frequency;
};
class Dictionary
{
public:
    bool isword(const string &word)
    {
        for (auto &ch : word)
        {
            if (!isalpha(ch))
            {
                return false;
            }
        }
        return true;
    }
    void read(const std::string &filename)
    {
        ifstream ifs(filename);
        if (!ifs.good())
        {
            cout << "ifs is not good" << endl;
            return;
        }
        string line;
        while (getline(ifs, line))
        {
            string word;
            istringstream iss(line);
            while (iss >> word)
            {
                if (isword(word))
                {
                    ++dict[word];
                }
            }
        }
    }
    void store(const std::string &filename)
    {
        ofstream ofs(filename);
        for (auto &elem : dict)
        {
            ofs << elem.first << " " << elem.second << endl;
        }
    }

private:
    map<string, int> dict;
};
void test()
{
    Dictionary dc;
    dc.read("The_Holy_Bible.txt");
    dc.store("wordcount.txt");
}
int main()
{
    test();
    return 0;
}
